<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>个人中心-会员</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/xadmin.css">
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/Swiper/3.4.2/css/swiper.min.css">
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/Swiper/3.4.2/js/swiper.jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/xadmin.js"></script>
</head>
<body>
<!-- 顶部开始 -->
<div class="container">
    <div class="logo"><a href="./index.html">健身房管理系统 V1.1</a></div>
    <div class="open-nav"><i class="iconfont">&#xe699;</i></div>
    <ul class="layui-nav right" lay-filter="">
        <li class="layui-nav-item">
            <a href="javascript:;">${logUsername}</a>
            <dl class="layui-nav-child"> <!-- 二级菜单 -->
                <dd><a href="${pageContext.request.contextPath}/member/toOneselfpage.action">个人中心</a></dd>
                <dd><a href="${pageContext.request.contextPath}/member/toMemcourseSchedule.action">课程表</a></dd>
                <dd><a href="${pageContext.request.contextPath}/member/outlogin.action">退出</a></dd>
            </dl>
        </li>
        <li class="layui-nav-item"><a href="/">前台首页</a></li>
    </ul>
</div>
<!-- 顶部结束 -->
<!-- 中部开始 -->
<div class="wrapper">
    <!-- 左侧菜单开始 -->
    <div class="left-nav">
        <div id="side-nav">
            <ul id="nav">
                <li class="list" current>
                    <a href="">
                        <i class="iconfont">&#xe761;</i>
                        欢迎页面
                        <i class="iconfont nav_right">&#xe697;</i>
                    </a>
                </li>
                <%--        教练--%>
                <li class="list">
                    <a href="${pageContext.request.contextPath}/member/toCoachpage.action">
                        <i class="iconfont">&#xe70b;</i>
                        教练查询
                        <i class="iconfont nav_right">&#xe697;</i>
                    </a>
                </li>
                <%--        课程管理--%>
                <li class="list">
                    <a href="${pageContext.request.contextPath}/member/toCoursepage.action">
                        <i class="iconfont">&#xe70b;</i>
                        课程查询
                        <i class="iconfont nav_right">&#xe697;</i>
                    </a>
                </li>
            </ul>
        </div>
    </div>
    <!-- 左侧菜单结束 -->
    <!-- 右侧主体开始 -->
    <div class="page-content">
        <div class="content">
            <!-- 右侧内容框架，更改从这里开始 -->
            <blockquote class="layui-elem-quote">
                个人中心
            </blockquote>
            <fieldset class="layui-elem-field layui-field-title site-title">
                <legend><a name="default">个人信息</a></legend>
            </fieldset>
            <table class="layui-table">
                <thead>
                    <tr>
                        <th>登录号码</th>
                        <th>登录密码</th>
                        <th>真名</th>
                        <th>性别</th>
                        <th>会员卡类型</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody id="tb1">
                <tr>
                    <td>${logUser.memlogname}</td>
                    <td>******</td>
                    <td>${logUser.memrealname}</td>
                    <td>${logUser.memsex}</td>
                    <td>${logUser.card.cardname}</td>
                    <td class="td-status">
                        <span class="layui-btn layui-btn-normal layui-btn-mini" onclick="member_edit('编辑','${pageContext.request.contextPath}/memOneself-edit.jsp','4','','400')">编辑</span>
                    </td>
                </tr>
                </tbody>
            </table>

            <fieldset class="layui-elem-field layui-field-title site-title">
                <legend><a name="default">会员卡消费记录</a></legend>
            </fieldset>
            <table class="layui-table">
                <thead>
                    <tr>
                        <th colspan="2" scope="col">消费信息</th>
                    </tr>
                </thead>
                <tbody id="tb2">
                    <tr>
                        <th width="30%">会员卡类型</th>
                        <td><span id="lbServerName">${logUser.card.cardname}</span></td>
                    </tr>
                    <tr>
                        <th width="30%">会员卡花费金额</th>
                        <td>${logUser.card.carmoney} 元</td>
                    </tr>
                    <tr>
                        <th width="30%">会员卡到期时间</th>
                        <td>
<%--                            将日期格式化输出，原来是中国标准化时间--%>
                            <fmt:formatDate value="${logUser.cardend}" pattern="YYYY 年 MM 月 dd 日"/>
                        </td>
                    </tr>
                </tbody>
            </table>

            <fieldset class="layui-elem-field layui-field-title site-title">
                <legend><a name="default">课程报名情况</a></legend>

            </fieldset>
            <table class="layui-table" id="tb3">
                <thead>
                <tr>
                    <th>课程名</th>
                    <th>上课周期</th>
                    <th>上课时间</th>
                    <th>任课教练</th>
                    <th>上课教室</th>
                    <th>课程价格</th>
                    <th>课程状态</th>
                </tr>
                </thead>
<%--                <tbody>--%>
<%--                <tr>--%>
<%--                    <td>item</td>--%>
<%--                    <td>item</td>--%>
<%--                    <td>item</td>--%>
<%--                    <td>item</td>--%>
<%--                    <td>item</td>--%>
<%--                    <td>item</td>--%>
<%--                    <td>--%>
<%--                        <c:if test="item =='0'">课程已结束</c:if>--%>
<%--                        <c:if test="item =='1'">报名阶段</c:if>--%>
<%--                        <c:if test="item =='2'">上课中</c:if>--%>
<%--                    </td>--%>
<%--                </tr>--%>
<%--                </tbody>--%>
            </table>
            <span id="tb3_span"></span>

            <fieldset class="layui-elem-field layui-field-title site-title">
                <legend><a name="default">教练预约情况</a></legend>
            </fieldset>
            <table class="layui-table" id="tb4">
                <thead>
                <tr>
                    <td hidden>预约表的id</td>
                    <th>教练</th>
                    <th>预约日期</th>
                    <th>修改日期</th>
                    <th>锻炼方向</th>
                    <th>联系电话</th>
                    <th>是否到期</th>
                </tr>
                </thead>
                <tbody id="tb44">
<%--                    <c:if test="${memResCoach!=null}">--%>
<%--                        <c:forEach var="rese" items="${memResCoach}">--%>
<%--                            <tr>--%>
<%--                                <td>${rese.coach.coachrealname}</td>--%>
<%--                                <td>--%>
<%--                                    <fmt:formatDate value="${rese.reservedate}" pattern="YYYY / MM / dd "/>--%>
<%--                                </td>--%>
<%--                                <td>${rese.coach.direction.direname}</td>--%>
<%--                                <td>--%>
<%--                                    <c:if test="${rese.reservestates==0}">--%>
<%--                                        到期--%>
<%--                                    </c:if>--%>
<%--                                    <c:if test="${rese.reservestates==1}">--%>
<%--                                        未到期--%>
<%--                                    </c:if>--%>
<%--                                </td>--%>
<%--                            </tr>--%>
<%--                        </c:forEach>--%>
<%--                    </c:if>--%>
                </tbody>
            </table>
                <span id="span_4"></span>
            <!-- 右侧内容框架，更改从这里结束 -->
        </div>
    </div>
    <!-- 右侧主体结束 -->
</div>
<!-- 中部结束 -->

<!-- 背景切换开始 -->
<!-- 背景切换结束 -->
<script>
    // 用户-编辑
    function member_edit (title,url,id,w,h) {
        x_admin_show(title,url,w,h);
    }
    //获取用户报名课程信息
    function infor() {
        $.ajax({
            url:"${pageContext.request.contextPath}/member/getAllCourse.action",
            type:"post",
            data:{memid:"${logUser.memid}"},
            dataType:"json",
            success:function (result) {
                if (result!=null){
                    //向第三个表格追加tbody
                    $(result).each(function (index,item){
                        var states;
                        //判断课程状态
                        if (item.course.coursestates=="0"){
                            states="课程已结束";
                        }else if (item.course.coursestates=="1"){
                            states="课程报名中";
                        }else if (item.course.coursestates=="2"){
                            states="课程已开始";
                        }
                        $("#tb3").append("<tbody><tr><td>"+item.course.coursename+"</td><td>"+item.course.coursestart+'~'+item.course.courseend+"</td>"+
                        "<td>"+item.course.week.weekname+'&nbsp;'+item.course.section.sectiontime+"</td><td>"+item.course.coach.coachrealname+"</td>"+
                        "<td>"+item.course.classroom.classroomname+"</td><td>"+item.course.coursemoney+"￥</td>" +
                        "<td>"+states+"</td></tr></tbody>");
                    });
                }
            },
            error:function (){
                console.log("您未报名任何课程error");
                $("#tb3_span").html("您未报名任何课程");
            }
        });
    }
    infor();
    //获取用户教练预约情况
    function infor2() {
        $.ajax({
            url:"${pageContext.request.contextPath}/member/getAllCoach.action",
            type:"post",
            data:{memid:"${logUser.memid}"},
            dataType:"json",
            success:function (result) {
                if (result!=null){
                    //先删除原来的
                    $("#tb44").children().remove();
                    $(result).each(function (index,item){
                        var states;
                        //判断课程状态
                        if (item.reservestates=="0"){
                            states="到期";
                        }else if (item.reservestates=="1"){
                            states="未到期";
                        }
                        $("#tb44").append("<tr><td hidden>"+item.reserveid+"</td><td>"+item.coach.coachrealname+"</td><td>"+item.reservedate+
                            "<td><span class='layui-btn layui-btn-normal layui-btn-mini' onclick='changeDate(this.parentNode.parentNode.firstChild)'>"+"编辑"+"</span></td>"+
                            "</td><td>"+item.coach.cotype+"</td><td>"+item.coach.coachLogName+"</td><td>"+states+"</td></tr>");
                    });
                }else {
                    $("#span_4").html("您未预约任何教练");
                }
            },
            error:function (){
                console.log("error");
            }
        });
    }
    infor2();
    //商定时间之后，自己修改。
    function changeDate(index) {
        console.log(index.innerText);
        $.ajax({
            url:"${pageContext.request.contextPath}/member/changeDate.action",
            type:"post",
            data:{reserveid:index.innerText},
            dataType:"text",
            success:function (result) {
                if (result=="ok"){
                    x_admin_show('日期修改','${pageContext.request.contextPath}/memdate-edit.jsp','','200');
                }else {
                    alert("无法修改");
                }
            },
            error:function (){
                alert("error");
            }
        });
    }
</script>
</body>
</html>
